function [F1, F11, F2, F3, F33, F4] = GAD_Etom_Cross_Day_RM_DeltaT(XDay_RM_Summary)
%% get cross-day RM vs deltaT for p-WTs

% G18
T1(:,1) = (extractfield(XDay_RM_Summary.G2_F4_18, 'Date1'))';
T1(:,2) = (extractfield(XDay_RM_Summary.G2_F4_18, 'Date2'))';
T1 = datetime(T1,'InputFormat','yyyy-MM-dd');

for n = 1:size(T1,1)
    deltaT1(n,1) = daysact(T1(n,1),T1(n,2));
end

RM1 (:,1) = extractfield(XDay_RM_Summary.G2_F4_18, 'Memory_Index');

% G28
T2(:,1) = (extractfield(XDay_RM_Summary.G2_F52_28, 'Date1'))';
T2(:,2) = (extractfield(XDay_RM_Summary.G2_F52_28, 'Date2'))';
T2 = datetime(T2,'InputFormat','yyyy-MM-dd');

for n = 1:size(T2,1)
    deltaT2(n,1) = daysact(T2(n,1),T2(n,2));
end

RM2 (:,1) = extractfield(XDay_RM_Summary.G2_F52_28, 'Memory_Index');

% G31
T3(:,1) = (extractfield(XDay_RM_Summary.G2_F52_31, 'Date1'))';
T3(:,2) = (extractfield(XDay_RM_Summary.G2_F52_31, 'Date2'))';
T3 = datetime(T3,'InputFormat','yyyy-MM-dd');

for n = 1:size(T3,1)
    deltaT3(n,1) = daysact(T3(n,1),T3(n,2));
end

RM3 (:,1) = extractfield(XDay_RM_Summary.G2_F52_31, 'Memory_Index');

% G34
T4(:,1) = (extractfield(XDay_RM_Summary.G2_F52_34, 'Date1'))';
T4(:,2) = (extractfield(XDay_RM_Summary.G2_F52_34, 'Date2'))';
T4 = datetime(T4,'InputFormat','yyyy-MM-dd');

for n = 1:size(T4,1)
    deltaT4(n,1) = daysact(T4(n,1),T4(n,2));
end

RM4 (:,1) = extractfield(XDay_RM_Summary.G2_F52_34, 'Memory_Index');

% G42
T5(:,1) = (extractfield(XDay_RM_Summary.G2_F62_42, 'Date1'))';
T5(:,2) = (extractfield(XDay_RM_Summary.G2_F62_42, 'Date2'))';
T5 = datetime(T5,'InputFormat','yyyy-MM-dd');

for n = 1:size(T5,1)
    deltaT5(n,1) = daysact(T5(n,1),T5(n,2));
end

RM5 (:,1) = extractfield(XDay_RM_Summary.G2_F62_42, 'Memory_Index');

% CCK37
T6(:,1) = (extractfield(XDay_RM_Summary.CCK_F6_37, 'Date1'))';
T6(:,2) = (extractfield(XDay_RM_Summary.CCK_F6_37, 'Date2'))';
T6 = datetime(T6,'InputFormat','yyyy-MM-dd');

for n = 1:size(T6,1)
    deltaT6(n,1) = daysact(T6(n,1),T6(n,2));
end

RM6 (:,1) = extractfield(XDay_RM_Summary.CCK_F6_37, 'Memory_Index');

% CaMK32
T7(:,1) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_32, 'Date1'))';
T7(:,2) = (extractfield(XDay_RM_Summary.CaMKIIa_F6_32, 'Date2'))';
T7 = datetime(T7,'InputFormat','yyyy-MM-dd');

for n = 1:size(T7,1)
    deltaT7(n,1) = daysact(T7(n,1),T7(n,2));
end

RM7 (:,1) = extractfield(XDay_RM_Summary.CaMKIIa_F6_32, 'Memory_Index');

%% Regression analysis for p-WT
% p-WT linear regression

T_pWT = cat(1,deltaT1,deltaT2,deltaT3,deltaT4,deltaT5,deltaT6,deltaT7);
RM_pWT = cat(1,RM1,RM2,RM3,RM4,RM5,RM6,RM7);

figure
F1 = fit(T_pWT,RM_pWT,'poly1');
plot(F1,T_pWT,RM_pWT,'ob');
xlabel('deltaT (days)')
ylabel('mean(RM correlation)')
set(gca, 'FontSize', 20)
title('p-WT', 'FontSize', 25)
ylim([0,0.4])
xlim([0,70])
legend('off')

F11 = fitlm(T_pWT,RM_pWT);

% p-WT exponential regression
figure
F2 = fit(T_pWT,RM_pWT,'exp1');
plot(F2,T_pWT,RM_pWT,'^b');
xlabel('deltaT (days)')
ylabel('mean(RM correlation)')
set(gca, 'FontSize', 20)
title('p-WT', 'FontSize', 25)
ylim([0,0.4])
xlim([0,70])
legend('off')




%% get cross-day RM vs deltaT for a5-i-KOs

% G18
T11(:,1) = (extractfield(XDay_RM_Summary.G2_F4_17, 'Date1'))';
T11(:,2) = (extractfield(XDay_RM_Summary.G2_F4_17, 'Date2'))';
T11 = datetime(T11,'InputFormat','yyyy-MM-dd');

for n = 1:size(T11,1)
    deltaT11(n,1) = daysact(T11(n,1),T11(n,2));
end

RM11 (:,1) = extractfield(XDay_RM_Summary.G2_F4_17, 'Memory_Index');

% G28
T22(:,1) = (extractfield(XDay_RM_Summary.G2_F52_21, 'Date1'))';
T22(:,2) = (extractfield(XDay_RM_Summary.G2_F52_21, 'Date2'))';
T22 = datetime(T22,'InputFormat','yyyy-MM-dd');

for n = 1:size(T22,1)
    deltaT22(n,1) = daysact(T22(n,1),T22(n,2));
end

RM22 (:,1) = extractfield(XDay_RM_Summary.G2_F52_21, 'Memory_Index');

% G31
T33(:,1) = (extractfield(XDay_RM_Summary.G2_F52_45, 'Date1'))';
T33(:,2) = (extractfield(XDay_RM_Summary.G2_F52_45, 'Date2'))';
T33 = datetime(T33,'InputFormat','yyyy-MM-dd');

for n = 1:size(T33,1)
    deltaT33(n,1) = daysact(T33(n,1),T33(n,2));
end

RM33 (:,1) = extractfield(XDay_RM_Summary.G2_F52_45, 'Memory_Index');

% G34
T44(:,1) = (extractfield(XDay_RM_Summary.G2_F52_53, 'Date1'))';
T44(:,2) = (extractfield(XDay_RM_Summary.G2_F52_53, 'Date2'))';
T44 = datetime(T44,'InputFormat','yyyy-MM-dd');

for n = 1:size(T44,1)
    deltaT44(n,1) = daysact(T44(n,1),T44(n,2));
end

RM44 (:,1) = extractfield(XDay_RM_Summary.G2_F52_53, 'Memory_Index');

% G42
T55(:,1) = (extractfield(XDay_RM_Summary.G2_F62_36, 'Date1'))';
T55(:,2) = (extractfield(XDay_RM_Summary.G2_F62_36, 'Date2'))';
T55 = datetime(T55,'InputFormat','yyyy-MM-dd');

for n = 1:size(T55,1)
    deltaT55(n,1) = daysact(T55(n,1),T55(n,2));
end

RM55 (:,1) = extractfield(XDay_RM_Summary.G2_F62_36, 'Memory_Index');

%% Regression analysis for a5-i-KO
% a5-i-KO linear regression

T_a5_i_KO = cat(1,deltaT11,deltaT22,deltaT33,deltaT44,deltaT55);
RM_a5_i_KO = cat(1,RM11,RM22,RM33,RM44,RM55);

figure
F3 = fit(T_a5_i_KO,RM_a5_i_KO,'poly1');
plot(F3,T_a5_i_KO,RM_a5_i_KO,'ob');
xlabel('deltaT (days)')
ylabel('mean(RM correlation)')
set(gca, 'FontSize', 20)
title('a5-i-KO', 'FontSize', 25)
ylim([0,0.4])
xlim([0,100])
legend('off')

F33 = fitlm(T_a5_i_KO,RM_a5_i_KO);

% a5-i-KO exponential regression
figure
F4 = fit(T_a5_i_KO,RM_a5_i_KO,'exp1');
plot(F4,T_a5_i_KO,RM_a5_i_KO,'^b');
xlabel('deltaT (days)')
ylabel('mean(RM correlation)')
set(gca, 'FontSize', 20)
title('a5-i-KO', 'FontSize', 25)
ylim([0,0.4])
xlim([0,100])
legend('off')

end